package com.my.meitianbackup.utils;

import java.awt.image.BufferedImage;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import javax.imageio.ImageIO;

public class ImgUtils {
	public static final String MOGUJIE = "MOGUJIE";
	public static final String TAOBAO = "TAOBAO";
	
	public static void getImg(String urlStr, String type) {

		URL url;
		try {
			url = new URL(urlStr);
			URLConnection connection = url.openConnection();
			connection.setDoOutput(true);
			BufferedImage image = ImageIO.read(connection.getInputStream());
			int srcWidth = image.getWidth(); // 源图宽度
			int srcHeight = image.getHeight(); // 源图高度
			
			if(type.equals(TAOBAO)) {
				if(srcWidth != srcHeight)
					return;
				if(srcWidth <= 240 || srcHeight <= 240)
					return;
			}
			
			if(type.equals(MOGUJIE)) {
				if(srcHeight / srcWidth != 3)
					return;
				if(srcWidth <= 240)
					return;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
